Linkedlist Attempt,recitating push_back function , print function,

Published

2025-09-26

Modified

2025-09-26

Attempt 1

Show the code
#include <stdio.h>
#include <stdlib.h>
typedef struct Node {
    int value;
    struct Node *next;
}Node;

Node* push_back(Node *last, int value);
void print_list(Node *head);

int main(void){
Node *head = NULL;
head = push_back(NULL,11111);
print_list(head);
return 0;
}

Node* push_back(Node *last, int value){
    if(last==NULL){
       last =(Node *)malloc(sizeof(last));
       last->value = value;
       last->next = NULL;
    }
}

void print_list(Node *head){
    for (Node *cur = head ; cur ; cur = cur->next)   // ❌ 这里没有让 cur 前进
        printf("%d", cur->value);
    printf("NULL\n");
}

    

execution result

11111NULL